package com.lb.statck.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lb.statck.mapper.shopcart.ShopcartMapper;
import com.lb.statck.pojo.dto.ShopDto;
import com.lb.statck.pojo.vo.ShopCartVO;
import com.lb.statck.service.ShopCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ShopCartServiceimpl implements ShopCartService {
    @Autowired
    private ShopcartMapper shopcartMapper;
    @Override
    public void insert(ShopDto shopDto) {
        //QueryWrapper
        int i = shopcartMapper.selectOne(shopDto);
        if (i>0)
        {
            int i1 = shopcartMapper.getNumber(shopDto) + 1;
            shopDto.setNumber(i1);

            shopcartMapper.update(shopDto);
        }
        else {
            shopcartMapper.insert(shopDto);
        }
    }

    @Override
    public List<ShopCartVO> get() {
        List<ShopCartVO> result=  shopcartMapper.get();
            return result;
    }

    @Override
    public void deleteShop(String userId) {
        shopcartMapper.deleteShop(userId);
    }

    @Override
    @Transactional
    public void updateNum(ShopDto shopDto) {
        shopcartMapper.update(shopDto);
    }
}
